/**
 * @param {number[]} digits 
 * @return {number[]}
 **/
var plusOne = function(digits) {
    let digits2=[];    
    while(digits.length-1>=0){        
        if(digits[digits.length-1]==9){            
            digits.pop();            
            digits2.push(0);        
        }else{            
            digits[digits.length-1]++;            
            break;        
        }    
    }    
    if(digits.length==0){        
        digits=[1,...digits2];    
    }else{        
        digits=[...digits,...digits2];    
    }    
    return digits;
};

let digits = [6,1,4,5,3,9,0,1,9,5,1,8,6,7,0,5,5,4,3];
console.log(plusOne(digits));